﻿//色彩选择器
(function(){
var Color512_64=function()
	{
	//Id:			生成色彩选择器的控件id
	//CurrentColor:		绑定当前选择色彩的输入框id
	//CurrentColorSpan:	显示当前选择色彩的控件id
	//OnClick:		点击色彩选择器事件处理
	//OnOver:		鼠标经过或离开色彩选择器事件处理
	//OnMove:		鼠标移动事件处理
	this.GetArgument(arguments[0],{Id:null,CurrentColor:null,CurrentColorSpan:null,OnClick:null,OnOver:null,OnMove:null},1);
	this.Image=fastCSharp.JsDomain+'js/htmlEditor/image/color512_64.bmp';
	};
(fastCSharp.Functions.Color512_64=Color512_64).Inherit(fastCSharp.BaseFunction,{
//载入色彩图片并初始化
Start:function()
	{
	var Iframe=this.GetId('iframe');
	this.$Id(this.Id).Html("<iframe Id='"+Iframe+"' name='"+Iframe+"' width='512px' height='64px' frameborder='0' marginwidth='0' marginheight='0' vspace='0' hspace='0' allowtransparency='true' scrolling='no'></iframe>");
	this.Iframe=frames[Iframe];
	this.Iframe.document.open();
	this.Iframe.document.write("<html><body><img id='Color512_64' src='"+this.Image+"' Width='512' Height='64' border='0' alt='点击改变最近选择的色彩参数' /></body></html>");
	this.Iframe.document.close();
	this.$(this.Iframe.document.getElementById('Color512_64')).AddEvent('mousemove',fastCSharp.ThisEvent(this,this.MoveColor,null,this.Iframe))
		.AddEvent('click',fastCSharp.ThisEvent(this,this.ClickColor,null,this.Iframe))
		.AddEvent('mouseover',fastCSharp.ThisFunction(this,this.Over,[1]))
		.AddEvent('mouseout',fastCSharp.ThisFunction(this,this.Over,[0]));
	this.$Id(this.CurrentColor).Set('maxLength',6).Value('000000').Set('readOnly',true).AddEvent('focus',function(){this.select();});
	if(this.CurrentColorSpan)
		{
		this.$Id(this.CurrentColorSpan).Css('backgroundColor','#000000').Set('title','点击改变最近选择的色彩参数').Cursor('pointer')
			.AddEvent('mouseover',fastCSharp.ThisFunction(this,this.Over,[1]))
			.AddEvent('mouseout',fastCSharp.ThisFunction(this,this.Over,[0]))
			.AddEvent('click',fastCSharp.ThisFunction(this,this.Click));
		}
	},
GetColor:function(Event)
	{
	var Width=Event.clientX,Height=Event.clientY,Color=(((Width>>5)<<4)+((Height>>5)<<3)+4)<<16;
	Color+=(((Height<32?Height:63-Height)<<3)+4)<<8;
	Width&=63;
	return Color+((Width<32?Width:63-Width)<<3)+4;
	},
MoveColor:function(Event)
	{
	this.Move(this.GetColor(Event));
	},
ClickColor:function(Event)
	{
	this.Click(this.GetColor(Event));
	},
//鼠标经过或离开色彩时调用this.OnOver(IsOver)
//IsOver:	为真表示经过,为假表示离开
Over:function(IsOver)
	{
	if(this.OnOver)	this.OnOver(IsOver);
	},
//鼠标移动后调用this.MoveFunction(Color),Color为当前指向的6位字符串的RGB色彩值
//Color:	色彩值
Move:function(Color)
	{
	Color=Color.toString(16).PadLeft(6,'0');
	this.$Id(this.CurrentColor).Value(Color);
	this.$Id(this.CurrentColorSpan).Css('backgroundColor','#'+Color);
	if(this.OnMove)	this.OnMove(Color);
	return Color;
	},
//鼠标点击后调用this.ClickFunction(Color),Color为当前指向的6位字符串的RGB色彩值
//Color:	色彩值
Click:function()
	{
	var Color=this.Move(parseInt(this.$Value(this.CurrentColor),16));
	if(this.OnClick)	this.OnClick(Color);
	},
Show:function(IsShow)
	{
	this.$Id(this.Id).Display(IsShow);
	this.$Id(this.CurrentColor).Display(IsShow);
	this.$Id(this.CurrentColorSpan).Display(IsShow);
	}
		});
})();